﻿using ApiConceptsFramework.HCs;
using FluentAssertions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;

namespace test.ApiConceptsFramework.HCs
{
	[TestFixture]
	public class ConfigStringTests
	{
		[Test]
		public void Returns_null_when_input_data_is_null()
		{
			new ConfigString().Evaluate(null, null, null, null).Should().BeNull();
		}

		[Test]
		public void Correctly_calculates_complexity_of_config_strings()
		{
			//Arrange
			var pattern = new ConfigString();
			var data = new ConfigStringInputData
				{
					ConfigStrings = new List<ConfigStringValue>
						{
							new ConfigStringValue {ConfigString = "configvalue1;configvalue2;configvalue3", NumberOfUsages = 1, PreviousUsages = 0},
							new ConfigStringValue {ConfigString = "configvalue1,configvalue2", NumberOfUsages = 1, PreviousUsages = 0},
						}
				};

			//Act
			var result = pattern.Evaluate(null, null, data, null);

			//Assert
			result.GeneralComplexity.Should().Be(0);
			result.ComplexityData.Should().HaveCount(2);
			result.ComplexityData[0].SearchComplexity.Should().Be(ConfigString.ConfigStringElementSearchComplexity*3);
			result.ComplexityData[1].SearchComplexity.Should().Be(ConfigString.ConfigStringElementSearchComplexity*2);
			result.ComplexityData[0].UsageComplexity.Should().Be(ConfigString.ConfigStringElementUsageComplexity*3);
			result.ComplexityData[1].UsageComplexity.Should().Be(ConfigString.ConfigStringElementUsageComplexity*2);
		}
	}
}
